/**
 *
 */
package com.angel.data.generator.builders.impl;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Collection;

import com.angel.common.helpers.AnnotationHelper;
import com.angel.common.helpers.ReflectionHelper;
import com.angel.data.generator.annotations.importFileProcessorRunner.ImportFileProcessorRunnerBuilder;
import com.angel.data.generator.annotations.inputStream.InputStreamBuilder;
import com.angel.data.generator.checkers.DataGeneratorChecker;
import com.angel.data.generator.interfaces.impl.AnnotationDataGenerator;
import com.angel.data.generator.preProcess.PreProcessStrategy;
import com.angel.data.generator.user.UserDataGenerable;

/**
 *
 * @author William
 * @since 21/August/2009.
 *
 */
public class DataUserGeneratorBuilder extends DataGeneratorAnnotationRunnerBuilder{

	private InputStream currentInputStream;
	
    public DataUserGeneratorBuilder(){
        super();
    }

    public DataUserGeneratorBuilder(Collection<DataGeneratorChecker> dataGeneratorCheckers){
        super(dataGeneratorCheckers);
    }

    public DataUserGeneratorBuilder(Collection<DataGeneratorChecker> dataGeneratorCheckers, PreProcessStrategy preProcessStrategy){
        super(dataGeneratorCheckers, preProcessStrategy);
    }

    @Override
    public <T> void addDataGeneratorClass(Class<T> dataGeneratorClass){
    	this.validateDataGeneratorClass(dataGeneratorClass);
    	UserDataGenerable userDataGenerable = (UserDataGenerable) ReflectionHelper.createObject(dataGeneratorClass);
    	userDataGenerable.setInputStream(this.getCurrentInputStream());
    	Method processorRunnerBuilderMethod = AnnotationHelper.getMethodWithAnnotation(dataGeneratorClass, ImportFileProcessorRunnerBuilder.class);
    	Method inputStreamBuilderMethod = AnnotationHelper.getMethodWithAnnotation(dataGeneratorClass, InputStreamBuilder.class);
    	AnnotationDataGenerator annotationDataGenerator = new AnnotationDataGenerator(userDataGenerable, processorRunnerBuilderMethod, inputStreamBuilderMethod);
    	super.addDataGenerator(annotationDataGenerator);
    }

	/**
	 * @return the currentInputStream
	 */
	public InputStream getCurrentInputStream() {
		return currentInputStream;
	}

	/**
	 * @param currentInputStream the currentInputStream to set
	 */
	public void setCurrentInputStream(InputStream currentInputStream) {
		this.currentInputStream = currentInputStream;
	}
}
